package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementsService;
import com.tanhua.server.service.QuanziMQService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * [评论] 模块
 */
@RestController
@RequestMapping("comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;
    @Autowired
    private MovementsService movementsService;
    @Autowired
    private QuanziMQService quanziMQService;

    /**
     * 查询单条动态的评论列表
     */
    @GetMapping
    public ResponseEntity<PageResult> queryCommentsList(@RequestParam("movementId") String publishId,
                                                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize) {
        PageResult pageResult = this.commentsService.queryCommentsList(publishId, page, pagesize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 发表评论
     */
    @PostMapping
    public ResponseEntity<Void> saveComments(@RequestBody Map<String, String> param) {
        String publishId = param.get("movementId");
        String content = param.get("comment");
        Boolean bool = this.commentsService.saveComments(publishId, content);
        return ResponseEntity.ok(null);
    }

    /**
     * 点赞
     */
    @GetMapping("/{publishId}/like")
    public ResponseEntity<Long> likeComment(@PathVariable("publishId") String publishId) {
        Long count = this.movementsService.likeComment(publishId);
        return ResponseEntity.ok(count);
    }

    /**
     * 取消点赞
     */
    @GetMapping("/{publishId}/dislike")
    public ResponseEntity<Long> disLikeComment(@PathVariable("publishId") String publishId) {
        Long count = this.movementsService.disLikeComment(publishId);
        return ResponseEntity.ok(count);
    }
}
